package com.nhim.cms.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CMSHelper {

	private static final Pattern TYPE_REGEX = Pattern.compile(
			"type\\s*=\\s*[\"'](.*?)[\"']", Pattern.CASE_INSENSITIVE);

	private static String getType(String text) {
		Matcher matcher = TYPE_REGEX.matcher(text);
		if (matcher.find()) {
			return matcher.group(1);
		}
		return "";
	}

	public static String processTag(String tag) {
		String result = "";
		String type = getType(tag);
		if ("".equals(type))
			return tag;

		try {
			switch (ItemType.valueOf(type.toUpperCase())) {
			case CONTENT:
				result = processContent(tag);
				break;
			case RESOURCE:
				result = processResource(tag);
				break;
			case FLEXTABLE:
				result = processFlextTable(tag);
				break;
			case ELEMENT:
				result = processElement(tag);
				break;

			}
			return result;

		} catch (Exception ex) {
			return tag;
		}

	}

	private static String processElement(String tag) {

		return "Element";
	}

	private static String processFlextTable(String tag) {

		return "FlexTable";
	}

	private static String processResource(String tag) {

		return "Resource";
	}

	private static String processContent(String tag) {
		return "Content";
	}

}
